<?php
namespace jy_weishop;
defined('BY_JYA') or exit('error');
/*
	订单，V8打印机：58mm（32字符），V9：80mm（42字符）
	设置字体大小、居中及切纸、来单提示音：http://www.jinyunzn.com/manage/index.php?plugin=core&action=article.show&nosession=1&id=11（出处：进云手册）
*/
class printtpl extends \plugin{
	public function upconttags($order=array(),$is_pay=0,$daike=0,$ptype=0,$pluginname='',$ordergoods=array(),$isadd=false){
		$isprint=false;
		$shopset=$this->plugin_setting('shopset');
		$paytypes=get_pay_types();
		$paytypes['peerpay']='找人代付';
		$paytypes['offpay']='线下收款';
		$paytypes['offsao']='线下扫码';
		$conttags=array_fields(array('ordersn','price','dispatchprice','remark','realname','mobile'),$order);
		$conttags['statustitle']=$this->order_status[$order['status']];
		$conttags['shopname']=$shopset['title']?:'shopname';
		$order['express']=$this->pdo_get('order_express',array('orderid'=>$order['id'],'opensend_type'=>0));
		$conttags['expresscom']=$this->model('model')->express_types()[$order['express']['express_id']]['name'];
		$conttags['expresssn']=$order['express']['expresssn'];
		//时间格式化
		$conttags['createtime']=date('Y-m-d H:i:s',$order['createtime']);
		$conttags['paytime']=date('Y-m-d H:i:s',$order['paytime']);
		$conttags['sendtime']=$order['express']['createtime']?date('Y-m-d H:i:s',$order['express']['createtime']):'';
		$conttags['finishtime']=date('Y-m-d H:i:s',$order['finishtime']);
		if($order['storeid']){
			$order['store']=pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['storeid']));
			$conttags['storetitle']=$order['store']['title'];
			$conttags['storeaddress']=$order['store']['address'];
			$conttags['storerealname']=$order['store']['realname'];
			$conttags['storemobile']=$order['store']['mobile']?:$order['store']['tel'];
			$order['store']['onlinetime']=json_decode($order['store']['onlinetime'],true);
			$conttags['storeonlinetime']=$order['store']['onlinetime']['start'].'~'.$order['store']['onlinetime']['end'];
		}
		
		if($order['merchid']){
			$order['store']=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['merchid']));
			$conttags['storetitle']=$order['store']['merchname'];
			$conttags['storeaddress']=$order['store']['address'];
			$conttags['storerealname']=$order['store']['realname'];
			$conttags['storemobile']=$order['store']['mobile']?:$order['store']['tel'];
			$order['store']['onlinetime']=json_decode($order['store']['onlinetime'],true);
			$conttags['storeonlinetime']=$order['store']['onlinetime']['start'].'~'.$order['store']['onlinetime']['end'];
		}
		//打印内容：
		if($ordergoods){
			$goodsstr=$this->model('printmsg')->getgoodsstr($ordergoods,'',$ptype);
			$conttags['goodsinfo']=$goodsstr['goodsinfo'];
			$conttags['goodsinfoold']=$goodsstr['goodsinfoold'];
		}
		$conttags['goodsnum']=0;
		foreach($ordergoods as $g){
			$g['total']=$g['total']?:1;
			$conttags['goodsnum'] +=$g['total'];
			if(!$conttags['goodsname']){
				$info=pdo_get('jy_weishop_goods',array('id'=>$g['goodsid']),array('title','pcate'));
				$conttags['goodsname']=$info['title'];
			}
		}
		$send_type=$this->send_types[$order['sendtype']];
		$selfinfo=pdo_get('jy_weishop_order_self',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order['id']));
		if($order['sendtype']==1){
			$send_type=$order['is_peisong']!=1?'快递配送':'同城配送';
		}elseif($order['sendtype']==2){
			if($order['isdish']==1){
				$send_type='店内';
			}else{
				$send_type='自提/店内';
			}
		}elseif($order['sendtype']==3){
			if($order['isdish']==1){
				$send_type='预约';
			}else{
				$send_type='虚拟物品';
			}
		}
		$conttags['send_type']=$send_type;
		$self_type='默认';
		$nickname=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['mid']),'nickname');
		if($selfinfo){
			if($order['isdish']==1){
				if($order['sendtype']==2){
					if($selfinfo['type']==1){
						$self_type='店内就餐';
					}else{
						$self_type='打包带走';
					}
				}elseif($order['sendtype']==1){
					if($selfinfo['type']==1){
						$self_type='普通';
					}else{
						$self_type='普通';
					}
				}
			}
			$username = $selfinfo['username']?:$order['username'];
			$mobile = $selfinfo['mobile']?:$order['mobile'];
			$address=$selfinfo['address'];
			$conttags['peitime']=$selfinfo['out_time']?:'立即配送';
		}
		if(!$selfinfo || $order['sendtype']==1){
			$order['address']=json_decode($order['address'],true);
			if($order['address'] && ($order['address']['name'] || $order['address']['mobile'])){
				$address=$order['address'];
			}else{
				$address=pdo_get('core_address',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['addressid']));
			}
			if(!is_array($address['pcd'])){
				$address['pcd']=json_decode($address['pcd'],true);
			}
			$username=$address && $address['name']?$address['name']:$nickname;
			$mobile=$address && $address['mobile']?$address['mobile']:$order['mobile'];
			$address=$address['pcd']['province'].' '.$address['pcd']['city'].' '.$address['pcd']['district'].' '.$address['pcd']['street'].''.$address['address'];
		}
		$conttags['selfnumber']=$selfinfo['number']?substr($selfinfo['number'],-4):substr($order['ordersn'],-4);
		$conttags['ordersn2']=substr($order['ordersn'],-6);
		if($daike){
			$username = $selfinfo['username']?$selfinfo['username']:'代客下单';
		}
		$is_pays =array('0'=>'未支付','1'=>'已支付');
		$conttags['self_type']=$self_type;
		$conttags['nickname']=$nickname;
		$conttags['username']=$username?:$nickname;
		$conttags['realname']=$conttags['realname']?:$conttags['username'];
		$conttags['mobile']=$mobile;
		$conttags['addressinfo']=$address;
		$conttags['lineold']=$this->strlen_pad('-',20,'-')."\n";
		if($ptype==1 || $ptype==8 || $ptype==9){
			$conttags['line']=$this->strlen_pad('-',30,'-')."\n";
		}elseif($ptype==2 || $ptype==3 || $ptype==7 || $ptype==10){
			$conttags['line']=$this->strlen_pad('-',47,'-')."\n";
		}
		if($order['ispay']){
			$conttags['paytitle']=$paytypes[$order['paytype']];
		}else{
			$conttags['paytitle']='无';
		}
		$conttags['ispay']=$is_pays[$order['ispay']];
		//if($order['sendtype'] == 2){
			if($order['tableid']){
				$table=pdo_get('jy_weishop_table',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['tableid']),array('title','group_id'));
				$grouptitle=pdo_getcolumn('jy_weishop_table_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$table['group_id']),'title');
				$conttags['tabletitle']=$grouptitle.'-'.$table['title'];
			}
		//}
		if(!$order['isdish'] || $order['sendtype']==1){
			$selfinfo['selftime']=$selfinfo['selftime']?date('Y-m-d H:i:s',$selfinfo['selftime']):'尽快配送';
			$conttags['selftime']=$selfinfo['out_time']?:$selfinfo['selftime'];
		}
		if($order['api_data']['usernum']){
			$conttags['usernum']=$order['api_data']['usernum'];
		}
		return $conttags;
	}
	public function upcontent($order,$textinfo=array(),$p=array(),$pluginname='',$ordergoods=array(),$isadd=false){
		$conttags=$textinfo['conttags'];
		if($p['templateid']){
				$datas=$this->gettpl_data($conttags);
				$tpl=pdo_get('jy_weishop_printer_template',array('id'=>$p['templateid'],'uniacid'=>$_SESSION['uniacid']));
				$content=$tpl['print_top']."\n";
				$tpl['print_data']=json_decode($tpl['print_data'],true);
				foreach($tpl['print_data'] as $tv){
					$value=$tv['value']."\n";
					$ltype='left';
					if($tv['textstytle']==1){
						$ltype='center';	
					}elseif($tv['textstytle']==2){
						$ltype='right';	
					}
					if($tv['type']=='toplogo'){
						if($p['type']==8 || $p['type']==10){
							$value=tomedia($tv['value']);
							$value=$value."\n";
							$value="<IMG l=".$ltype.">".$value."</IMG>";
						}elseif($p['type']==7 || $p['type']==9){
							$value="<LOGO>";
						}else{
							$value='';
						}
					}elseif($tv['type']=='goodsinfo'){
						$value=$tv['fontstytle']?$textinfo['goodsinfo2']:$textinfo['goodsinfo'];
					}elseif($tv['type']=='ewm'){
						$value=tomedia($tv['value']);
						if($p['type']==7 || $p['type']==9){
							$value="<QR>".$value."</QR>";
						}elseif($p['type']==8 || $p['type']==10){
							$value="<QRCODE s=3 e=L l=".$ltype.">".$value."</QRCODE>";
						}else{
							$value="<AM><QR_T>QR_CODE</QR_T><QR_S>5</QR_S><QR_D>".$value."</QR_D></AM>";
						}
					}elseif($tv['type']=='code'){
						
					}elseif($tv['type']=='line'){
						if($p['type']==1 || $p['type']==8  || $p['type']==9){
							$value=$this->strlen_pad('-',30,'-')."\n";
						}elseif($p['type']==2 || $p['type']==3 || $p['type']==7  || $p['type']==10){
							$value=$this->strlen_pad('-',47,'-')."\n";
						}
					}else{
						if($tv['fontstytle']){
							$value="<S".$tv['fontstytle'].">".$value."</S".$tv['fontstytle'].">";
						}
						if($tv['bold']){
							$value="<B>".$value."</B>";
						}
						if($tv['textstytle']==1){
							$value="<AM>".$value."</AM>";
						}elseif($tv['textstytle']==2){
							$value="<AR>".$value."</AR>";
						}
					}
					$content .=$value;
				}
				//print_r($datas);exit;
				$content=model('core/account')->replaceTemplate($content,$datas);
				return $content;
		}
		$print_top=$content1=$content2=$content3=$print_end='';
		if($p['print_toplogo'] && ($p['type']==7 || $p['type']==8 || $p['type']==9 || $p['type']==10)){
			if($p['type']==8 || $p['type']==10){
				$print_top .="<IMG>".$p['print_toplogo']."</IMG>\n";
			}elseif($p['type']==7 || $p['type']==9){
				$print_top .="<LOGO>";
			}
		}
		if($p['print_top']){
			$print_top .="<AM>".$p['print_top']."\n</AM>";
		}
		if($order['sendtype'] == 2){
			$content1="<AM><B><S2>".$conttags['selfnumber']."\n</S2></B></AM>";
			if($conttags['tabletitle']){
				$content1="<AM><B><S2>桌号:".$conttags['tabletitle']."\n</S2></B></AM>";
			}
		}else{
			$content1="<B><S2>".$conttags['ordersn2']."\n</S2></B>";
		}
		$p['print_ewm']=$p['print_ewm']?custom_url($p['print_ewm'],true):'';
		$p['print_toplogo']=tomedia($p['print_toplogo']);
		//单商品打印,单商品标签打印
		if($p['tpl_type']==1){
	    	$content2=$textinfo['goodsinfo'];	
		}elseif($p['tpl_type']==2){
			//40*30标签
			$print_top='';
			$content1 ='<PAGE>';
			$content2 ='<SIZE>40,30</SIZE>';
			$content2 .='<TEXT x="8" y="8" w="2" h="1" r="0">'.$textinfo['goodsinfo']['title'].'</TEXT>';
			if($textinfo['goodsinfo']['optiondata']){
				$content2 .='<TEXT x="8" y="66" w="1" h="1" r="0">'.$textinfo['goodsinfo']['optiondata']."</TEXT>";
			}
			$content2 .='<TEXT x="230" y="96" w="2" h="1" r="0">'.$textinfo['goodsinfo']['total'].'份</TEXT>';
			$content2 .='<TEXT x="8" y="136" w="1" h="1" r="0">'.$conttags['createtime'].'</TEXT>';
			$print_end .='<TEXT x="8" y="176" w="1" h="1" r="0">'.$conttags['selfnumber'].'</TEXT>';
			if($p['print_ewm']){
				$print_end .='<QR x="180" y="176" e="L" w="98">'.$p['print_ewm']."</QR>";
			}
		}elseif($p['tpl_type']==3){
			//40*60标签
			$print_top='';
			$content1='<PAGE>';
			$content1 .='<SIZE>40,60</SIZE>';
			$content1 .='<TEXT x="8" y="8" w="2" h="1" r="0">'.$conttags['shopname'].'</TEXT>';
			$content1 .='<TEXT x="8" y="46" w="1" h="1" r="0">'.$p['print_top'].'</TEXT>';
			$content1 .='<TEXT x="8" y="70" w="1" h="1" r="0">'.$this->strlen_pad('-',20,'-').'</TEXT>';
			$content2='<TEXT x="8" y="100" w="2" h="1" r="0">'.$textinfo['goodsinfo']['title'].'</TEXT>';
			if($textinfo['goodsinfo']['optiondata']){
				$content2 .='<TEXT x="8" y="136" w="2" h="1" r="0">'.$textinfo['goodsinfo']['optiondata'].'</TEXT>';
			}
			if($textinfo['goodsinfo']['total']==1){
				$content2 .='<TEXT x="8" y="170" w="2" h="1" r="0">1/1</TEXT>';
			}else{
				$content2 .='<TEXT x="8" y="170" w="2" h="1" r="0">jytotal#'.$textinfo['goodsinfo']['total'].'</TEXT>';
			}
			$content2 .='<TEXT x="8" y="210" w="1" h="1" r="0">'.$conttags['createtime'].'</TEXT>';
			if($p['print_remark']){
				$content2 .='<TEXT x="8" y="255" w="1" h="1" r="0">'.$p['print_remark'].'</TEXT>';
			}
			$content2 .='<TEXT x="8" y="310" w="1" h="1" r="0">'.$this->strlen_pad('-',40,'-').'</TEXT>';
			if($p['print_end']){
				//$print_end .='<TEXT x="8" y="430" w="1" h="1" r="0">'.$p['print_end'].'</TEXT>';
			}
			$print_end .='<TEXT x="28" y="360" w="2" h="2" r="0">'.$conttags['selfnumber'].'</TEXT>';
			if($p['print_ewm']){
				$print_end .='<QR x="180" y="345" e="L" w="98">'.$p['print_ewm']."</QR>";
			}
		}else{
			$content1 .="<AM>".$conttags['createtime']."\n</AM>";
			$content2=$textinfo['goodsinfo'];
			if(!$isadd){
				$content3 ='商品合计:'.$order['goodsprice']."\n";
				if($order['level_de_price']>0){		
					$content3 .='会员折扣:'.$order['level_de_price']."\n";
				}
				if($order['dispatchprice']>0){
					$content3 .='运费:'.$conttags['dispatchprice']."\n";
				}
				if($order['enough_de_price']>0){
					$content3 .='满额减:'.$order['enough_de_price']."\n";
				}
				if($order['coupon_de_price']>0){
					$content3 .='优惠券减:'.$order['coupon_de_price']."\n";
				}
				$content3 .='实收:'.$conttags['price']."\n";
				$content3 .='下单时间:'.$conttags['createtime']."\n";
				$content3 .='订单类型:'.$conttags['send_type'].'-('.$conttags['self_type'].")\n";		
				$content3 .='是否支付:'.$conttags['ispay'].'-('.$conttags['paytitle'].")\n";
				if($order['sendtype']==1){//快递配送
					$content3 .='收货人:'.$conttags['username']."\n";
					$content3 .='收货手机:'.$conttags['mobile']."\n";
					$content3 .='配送地址:'.$conttags['addressinfo']."\n";
					$content3 .="配送时间：".$conttags['selftime']."\n";
				}elseif($order['sendtype']==2){//自提/店内
					$content3 .='下单人:'.$conttags['username']."\n";
					$content3 .='联系电话:'.$conttags['mobile']."\n";
				}elseif($order['sendtype']==3){//虚拟商品
					$content3 .='下单人:'.$conttags['username']."\n";
					$content3 .='联系电话:'.$conttags['mobile']."\n";
				}
				if($conttags['remark']){
					$content3 .='备注:'.$conttags['remark']."\n";
				}
				if($p['print_remark']){
					$content3 .=$p['print_remark']."\n";
				}
			}
			if($p['print_end']){
				$print_end .=$p['print_end']."\n";
			}
			if($p['print_ewm']){
				if($p['type']==7 || $p['type']==9){
					$print_end .="<QR>".$p['print_ewm']."</QR>";
				}elseif($p['type']==8 || $p['type']==10){
					$print_end .="<QRCODE s=4 e=L l=center>".$p['print_ewm']."</QRCODE>";
				}else{
					$print_end .="<AM><QR_T>QR_CODE</QR_T><QR_S>5</QR_S><QR_D>".$p['print_ewm']."</QR_D></AM>";
				}
			}
			if($p['print_store']){
				$print_end .=$conttags['storetitle']."\n";
				$print_end .=$conttags['storemobile']."\n";
			}
		}
		if($p['tpl_type']==2 || $p['tpl_type']==3){
			$conttags['line']='';
		}
		$content=$print_top;
		if($print_top){
			$content .=$conttags['line'];
		}
		$content .=$content1;
		$content .=$conttags['line'];
		$content .=$content2;
		$content .=$conttags['line'];
		if($content3){
			$content .=$content3;
			$content .=$conttags['line'];
		}
		$content .=$print_end;
		if($p['tpl_type']==2 || $p['tpl_type']==3){
			$content .='</PAGE>';
		}
		//file_put_contents(ROOT_D.'/1.txt',$content);
		return $content;
	}
	public function gettpl_data($conttags=array()){
		$datas = array(
			array('name' => '商城名称', 'value' => $conttags['shopname']),
			array('name' => '粉丝昵称', 'value' => $conttags['nickname']),
			array('name' => '订单号', 'value' => $conttags['ordersn']),
			array('name' => '订单金额', 'value' => $conttags['price']),
			array('name' => '订单状态', 'value' => $conttags['statustitle']),
			array('name'=>'配送方式','value'=>$conttags['send_type']),
			array('name' => '运费', 'value' => $conttags['dispatchprice']),
			array('name' => '快递公司', 'value' => $conttags['expresscom']),
			array('name' => '快递单号', 'value' => $conttags['expresssn']),
			array('name' => '收件人', 'value' => $conttags['realname']),
			array('name' => '购买者姓名', 'value' => $conttags['username']),
			array('name' => '购买者电话', 'value' => $conttags['mobile']),
			array('name' => '收货地址', 'value' => $conttags['addressinfo']),
			array('name'=>'支付方式','value'=>$conttags['paytitle']),
			array('name' => '下单时间', 'value' => $conttags['createtime']),
			array('name' => '支付时间', 'value' => $conttags['paytime']),
			array('name' => '发货时间', 'value' => $conttags['sendtime']),
			array('name' => '配送时间', 'value' => $conttags['peitime']),
			array('name' => '收货时间', 'value' => $conttags['finishtime']),
			array('name' => '取消时间', 'value' => $conttags['canceltime']),
			array('name' => '门店', 'value' => $conttags['storetitle']),
			array('name' => '门店地址', 'value' => $conttags['storeaddress']),
			array('name' => '门店联系人', 'value' => $conttags['storerealname']),
			array('name' => '门店联系人电话', 'value' => $conttags['storemobile']),
			array('name' => '门店营业时间', 'value' => $conttags['storeonlinetime']),
			//array('name' => '虚拟物品自动发货内容', 'value' => $conttags['canceltime']),
			//array('name' => '虚拟卡密自动发货内容', 'value' =>$conttags['canceltime']),
			array('name' => '自提码', 'value' => $conttags['selfnumber']?:'无'),
			array('name' => '桌号', 'value' => $conttags['tabletitle']?:'无'),
			array('name' => '客户人数', 'value' => $conttags['usernum']),
			array('name' => '备注信息', 'value' => $conttags['remark']?:'无'),
			array('name' => '商品数量', 'value' => $conttags['goodsnum']),
			array('name' => '商品名称', 'value' => $conttags['goodsname']),
			array('name' => '排队号', 'value' => $conttags['selfnumber']?:'无'),
			array('name' => '当前时间', 'value' => date('Y-m-d H:i:s',time())),
		);
		return $datas;
	}
	public function datademo(){
		$datademo=array();
		$datademo[]=array('type'=>'toplogo','textstytle'=>1,'value'=>'../addons/jy_weishop/resource/images/plogo.png');
		$datademo[]=array('type'=>'text','textstytle'=>1,'value'=>'一杯好茶饮，不单单是好的原料，更重要的是传递的核心理念。创始人希望通过这杯茶饮将快乐传递给每个人，让"不开心就喝果茶!"成为潮流年轻、时尚标语。');
		$datademo[]=array('type'=>'text','textstytle'=>1,'value'=>'合作电话：400-666-888');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'text','textstytle'=>1,'bold'=>1,'fontstytle'=>3,'bold'=>1,'value'=>'[自提码]');
		$datademo[]=array('type'=>'text','textstytle'=>1,'value'=>'[下单时间]');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'goodsinfo','value'=>'');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'text','value'=>'消费合计：[订单金额]');
		$datademo[]=array('type'=>'text','value'=>'支付方式：[支付方式]');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'ewm','textstytle'=>1,'value'=>custom_url('jy_weishop/index/',true));
		return $datademo;
	}
	public function datademo1(){
		$datademo=array();
		$datademo[]=array('type'=>'text','textstytle'=>1,'bold'=>1,'fontstytle'=>3,'bold'=>1,'value'=>'[自提码]');
		$datademo[]=array('type'=>'text','textstytle'=>1,'value'=>'[下单时间]');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'goodsinfo','value'=>'');
		$datademo[]=array('type'=>'line','value'=>'');
		return $datademo;
	}
	public function datademo2(){
		$datademo=array();
		$datademo[]=array('type'=>'text','textstytle'=>1,'bold'=>1,'fontstytle'=>3,'value'=>'店铺名称');
		$datademo[]=array('type'=>'text','textstytle'=>1,'value'=>'[自提码]');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'goodsinfo','value'=>'');
		$datademo[]=array('type'=>'line','value'=>'');
		return $datademo;
	}
	public function datademo3(){
		$datademo=array();
		$datademo[]=array('type'=>'text','textstytle'=>1,'bold'=>1,'fontstytle'=>3,'value'=>'店铺名称');
		$datademo[]=array('type'=>'text','textstytle'=>1,'value'=>'合作电话：400-666-888');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'text','textstytle'=>1,'bold'=>1,'fontstytle'=>3,'bold'=>1,'value'=>'[自提码]');
		$datademo[]=array('type'=>'text','textstytle'=>1,'value'=>'[下单时间]');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'goodsinfo','value'=>'');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'text','value'=>'消费合计：[订单金额]');
		$datademo[]=array('type'=>'text','value'=>'支付方式：[支付方式]');
		$datademo[]=array('type'=>'line','value'=>'');
		$datademo[]=array('type'=>'ewm','textstytle'=>1,'value'=>custom_url('jy_weishop/index/',true));
		return $datademo;
	}
	public function strlen_pad($str,$alllen,$zifu='')//补齐空格
	{
		//真实字符串长度（一个中文=2）
		$len = (strlen($str)+mb_strlen($str,'UTF-8'))/2;
		$buqi = '';
		for($i=0;$i<($alllen-$len);$i++){
			$buqi .= $zifu?:' ';
		}
		$new_str = $str.$buqi;
		return $new_str;
	}
}
